<!-- $Id $ -->
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js,validator.js,selectzone3.js?t=1"}
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
<div class="main-div">
<form method="post" action="package.php" name="theForm" onsubmit="return validate()">
<table cellspacing="1" cellpadding="3" width="100%">
  <tr>
    <td class="label">{$lang.lab_package_name}</td>
    <td><input type="text" name="package_name" maxlength="60" size="40" value="{$package.package_name}" />{$lang.require_field}</td>
  </tr>

  <tr>
    <td class="label">{$lang.lab_package_buy_min}</td>
    <td><input type="text" name="buy_min" size="10" value="{$package.buy_min}"/>{$lang.require_field}</td>
  </tr>

	<!--
    <tr>
    <td class="label">活动类型：</td>
    <td>
		{foreach from=$activity_list item=data}
			<input type="checkbox" name="act_types[]" {if $data.checked eq 1}checked="checked"{/if} value="{$data.bb_id}"/><label>{$data.bb_name}</label>
		{/foreach}
	</td>
  </tr>-->

  <tr>
    <td class="label">活动类型：</td>
    <td><select name="act_type2">{$activity_list_options}</select></td>
  </tr>

  <tr>
    <td class="label">商品组合描述：</td>
    <td>{$FCKeditor3}</td>
  </tr>
  <!-- 商品搜索 -->
  <tr>
    <td class="label">
      {$lang.lab_search_goods}
    </td>
    <td>
      <select name="cat_id"><option value="0">{$lang.all_category}</caption>{$cat_list}</select>
      <input type="text" name="keyword" />
      <input type="button" value="{$lang.button_search}" onclick="javascript:searchGoods();" class="button" />
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <table id="groupgoods-table" align="center" style="width:90%;">
        <!-- 商品列表 -->
        <tr>
          <th>{$lang.all_goods}</th>
          <th>{$lang.handler}</th>
          <th>{$lang.package_goods}</th>
        </tr>
        <tr>
          <td width="20%">
            <select name="source_select" size="15" style="width:100%" onchange="this.form.elements['number'].value = 1" ondblclick="sz.addItem(false, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)">
            </select>
          </td>
          <td align="center">
            <p><input name="number" type="hidden" size="6" value="1" /></p>
            <p><input type="button" value="添加" onclick="sz.addItem(false, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)" class="button" /></p>
            <p><input type="button" value="移除" onclick="sz.dropItem(false, 'drop_package_goods', this.form.elements['id'].value)" class="button" /></p>
           
          </td>
          <td width="70%" style="border:1px solid #DDD;">
			<table width="100%" id="goods_aa_list" cellspacing="0" borderColor="#DDD" border="1" cellpadding="0" style="border:1px solid #DDD;width:100%;">
					 {foreach from=$package_goods_list item=package_goods}
					<tr id="tr_{$package_goods.goods_id}">
						<td width="50" align="center"><input type="checkbox" name="box_select" value="{$package_goods.goods_id}"/></td>
						<td style="padding:5px;">
							商品名称：{$package_goods.goods_name}<br/>
							所属商品：{$package_goods.cat_name}<br/>
							商品尺寸：{$package_goods.goods_size}
						</td>
						<td style="padding:5px;"><p style="margin:0;padding:0;line-height:22px;">
							商品型号：<select name="goods_model[{$package_goods.goods_id}]">
							<option value="0">选择型号</option>
							<option {if $package_goods.goods_model eq "1"}selected{/if} value="1">经济型</option>
							<option {if $package_goods.goods_model eq "2"}selected{/if} value="2">标准型</option>
							<option {if $package_goods.goods_model eq "3"}selected{/if} value="3">豪华型</option></select><br/>
							商品数量：<input type="text" size="20" value="{$package_goods.goods_number}" name="goods_number[{$package_goods.goods_id}]"/><br/>
							市场价：<input type="text" size="20" value="{$package_goods.market_price}" name="market_price[{$package_goods.goods_id}]"/><br/>
							商城价：<input type="text" size="20" value="{$package_goods.shop_price}" name="shop_price[{$package_goods.goods_id}]"/><br/>
							促销价：<input type="text" size="20" value="{$package_goods.goods_price}" name="goods_price[{$package_goods.goods_id}]"/>
							</p>
						</td>
					</tr>
					 {/foreach}
				</table>

			<select name="target_select" size="15" style="width:100%;display:none;" multiple ondblclick="sz.dropItem(false, 'drop_package_goods', this.form.elements['id'].value)">
              {foreach from=$package_goods_list item=package_goods}
              <option value="{$package_goods.goods_id}">{$package_goods.goods_name}</option>
              {/foreach}
            </select>
          </td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    <td colspan="2" align="center">
      <input type="submit" value="{$lang.button_submit}" class="button" />
      <input type="reset" value="{$lang.button_reset}" class="button" />
      <input type="hidden" name="act" value="{$form_action}" />
      <input type="hidden" name="id" value="{$package.id}" />
    </td>
  </tr>
</table>
</form>
</div>
<script language="JavaScript">
<!--
{literal}
document.forms['theForm'].elements['package_name'].focus();
var elements = document.forms['theForm'].elements;
var sz = new SelectZone(2, elements['source_select'], elements['target_select'], elements['number']);
onload = function()
{
    // 开始检查订单
    startCheckOrder();
}

/**
 * 检查表单输入的数据
 */
function validate()
{
    validator = new Validator("theForm");
    validator.required("package_name",  no_name);
    //validator.isNullOption("goods_id", no_goods_id);
    //validator.isTime("start_time", invalid_starttime, true);
   // validator.isTime("end_time", invalid_endtime, true);
   // validator.gt("end_time", "start_time", invalid_gt);
   // validator.isNumber("package_price", invalid_package_price, true);
	validator.isNumber("buy_min", invalid_package_price, true);
    if (document.forms['theForm'].elements['act'] == "insert")
    {
        validator.required("password", no_password);
    }
	var bm = document.forms['theForm'].elements['buy_min'].value;
	var mm = document.getElementById('goods_aa_list').rows.length;
	if(bm>mm){
		 validator.addErrorMsg(buy_min_error);
	}

    return validator.passed();
}

function searchGoods()
{
    var filter = new Object;
    filter.keyword    = document.forms['theForm'].elements['keyword'].value;
    filter.cat_id     = document.forms['theForm'].elements['cat_id'].value;
    //filter.brand_id   = document.forms['theForm'].elements['brand_id'].value;

    Ajax.call('package.php?is_ajax=1&act=search_goods', filter, searchGoodsResponse, 'GET', 'JSON')
}

function searchGoodsResponse(result)
{
  var frm = document.forms['theForm'];
  var sel = frm.elements['source_select'];

  if (result.error == 0)
  {
    /* 清除 options */
    sel.length = 0;

    /* 创建 options */
    var goods = result.content;
    if (goods)
    {
        for (i = 0; i < goods.length; i++)
        {
            /* 货品 options */
            if (goods[i].products.length > 0)
            {
              for (var j = 0; goods[i].products[j]; j++)
              {
                var opt = document.createElement("OPTION");
                opt.value = goods[i].value + '_' + goods[i].products[j].product_id;
                opt.text  = goods[i].text + '[' + goods[i].products[j].goods_attr_str + ']';
                sel.options.add(opt);
              }
            }
            else
            {
              var opt = document.createElement("OPTION");
              opt.value = goods[i].value;
              opt.text  = goods[i].text;
              sel.options.add(opt);
            }
        }
    }
    else
    {
        var opt = document.createElement("OPTION");
        opt.value = 0;
        opt.text  = search_is_null;
        sel.options.add(opt);
    }
  }

  if (result.message.length > 0)
  {
    alert(result.message);
  }
}

/* 关联商品函数 */
//function searchGoods_list(szObject, catId, brandId, keyword)
//{
//  var filters = new Object;
//
//  filters.cat_id = elements[catId].value;
//  filters.brand_id = elements[brandId].value;
//  filters.keyword = Utils.trim(elements[keyword].value);
//
//  szObject.loadOptions('get_goods_list', filters);
//}
//-->
{/literal}
</script>
{include file="pagefooter.htm"}